local UIBase = require("view.UIBase")
local NpcTalkCell = class("NpcTalkCell", UIBase)

function NpcTalkCell:ctor(parent, npcId)
    local resource = {
        path = "Prefabs/View/Npc",
        name = "NpcTalkCell",
        parent = parent.gameObject
    }
    self._parent = parent
    self._npcId = npcId
    NpcTalkCell.super.ctor(self, resource)
end

function NpcTalkCell:start()
    G_UIUtil.addTouchEvent(self._imageBg.transform, nil, nil, handler(self, self._onTouchClick))
    local cfg = require("config.npc").get(self._npcId)
    self._textName.text = cfg.name
    self._cfg = cfg
end

function NpcTalkCell:getNpcId()
    return self._npcId
end

function NpcTalkCell:_onTouchClick()
    printDebug(" NpcTalkCell:_onTouchClick")
    local pop = require("gameLogic.story.storyUI.PopupStoryChat").new()
    pop:updateUI(self._cfg.storyId)
    pop:setCallback(
        function()
            local gotoFunc = self["_goto_" .. self._cfg.jump]
            if gotoFunc then
                gotoFunc(self)
            end
            self._parent:close()
        end
    )
end

function NpcTalkCell:_goto_shop()
    local shop = require("view.shop.ShopView").new()
end

function NpcTalkCell:_goto_monsterhole()
    local monsterhole = require("view.mosnterHole.MonsterHoleView").new()
end

return NpcTalkCell
